package com.orangelife.mobile.surrounding.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.curry.android.util.ImageDownloader;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.surrounding.entity.GoodsEntity;
import com.orangelife.mobile.common.fragment.OrangeLifeBaseFragment;
import com.orangelife.mobile.widget.imagegridview.ImageGridView;

import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by YangWei
 * on 2015/10/16.
 */
public class CommercialDetailFragment extends OrangeLifeBaseFragment {

    @Bind(R.id.tvSalesTime)
    TextView tvSalesTime;
    @Bind(R.id.tvAddress)
    TextView tvAddress;
    @Bind(R.id.ivSendRange)
    ImageView ivSendRange;
    @Bind(R.id.gvPhoto)
    ImageGridView gvPhoto;
    private View ambitusView;

    private ImageDownloader image= ImageDownloader.getImageDownloader();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (ambitusView == null) {
            ambitusView = inflater.inflate(R.layout.fragment_circumtesco_commercial,
                    null);
            ButterKnife.bind(ambitusView);
            findView();

        }
        /*
		 * 缓存的rootView需要判断是否已经被加过parent，
		 * 如果有parent需要从parent删除，要不然会发生这个view已经有parent的错误。
		 */
        ViewGroup parent = (ViewGroup) ambitusView.getParent();
        if (parent != null) {
            parent.removeView(ambitusView);
        }
        ButterKnife.bind(this, ambitusView);
        return ambitusView;
    }

    /**
     * 赋值
     */
    private void findView() {
        Map<String,Object> map = GoodsEntity.getMap();
        tvSalesTime.setText(map.get("shopHours").toString());
        tvAddress.setText(map.get("stree").toString());
        String url=map.get("dispatchingImg").toString();
        image.download(url, ivSendRange, ImageDownloader.ImageSize.IMAGE_SIZE_MIDDLE_JPG);
        String pics = map.get("merchantImgs").toString();
        gvPhoto.init(getActivity(), pics, "##");

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
